package com.guan.ordering_sys.generator.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guan.ordering_sys.common.PageResult;
import com.guan.ordering_sys.common.ResultApi;
import com.guan.ordering_sys.generator.service.OrderDetailService;
import com.guan.ordering_sys.vo.OrderDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 韩思琪
 * @since 2021-06-18
 */
@Api(tags = "订单明细表控制器")
@RestController
@RequestMapping("/generator/order-detail")
public class OrderDetailController {

    @Autowired
    OrderDetailService orderDetailService;

    @ApiOperation(value ="订单明细列表")
    @PostMapping("/orderDetailList")
    public ResultApi orderDetailList(@ApiParam("当前页") @RequestParam(required = true) int pageNum,
                                     @ApiParam("页面大小") @RequestParam(required = true) int pageSize,
                                     @ApiParam("订单id") @RequestParam(required = true) int orderId){
        Page<OrderDetailVo>  orderDetailVoPage = new Page<>();
        orderDetailVoPage.setCurrent(pageNum);
        orderDetailVoPage.setSize(pageSize);

        IPage<OrderDetailVo> orderDetailVoIPage = orderDetailService.orderDetailList(orderDetailVoPage,orderId);
        PageResult<OrderDetailVo> orderDetailVoPageResult = new PageResult<>(orderDetailVoPage.getRecords().size(),orderDetailVoIPage.getRecords());
        return ResultApi.success(orderDetailVoPageResult);
    }

}

